#ifndef __STORAGE_H__
#define __STORAGE_H__

#include "fw/vbb_Queue.h"
#include "fw/vbb_USART.h"
#include "fw/vbb_Flash.h"

#ifndef CONFIG_STM32G_MAINTAIN

typedef struct
{    
    // Network Settings
    char    HTTPServerAddr[32];
    char    HTTPServerPort[8];
    
    char    HTTPServerAddr2[32];
    char    HTTPServerPort2[8];
    
    int     MessagePerHour_Move;
    int     MessagePerHour_Idle;    
    int     ServerMessagePerHour;
    
    // Information
    char    OwnerId[32];
    char    VehicleId[32];
    char    VehicleModel[32];
    char    DeviceModel[32];
    char    PlateNumber[32]; 
    char    FirmwareDir[128];
    char    FirmwarePrefix[32];
    char    DriverName[128];
    char    VIN[128];
    
    // BGTVT
    int     WarningVelocity;
    
    //Sensor
    bool    ActiveOnHigh_Door;
    bool    ActiveOnHigh_Engine;
    bool    ActiveOnHigh_AC;
    
    bool    HTTP_ProtocolEnable;
        
    int     PulseOnKm;    
    bool    OfflineMode;        
} VBB_Config;

#else

#define HTTP_ADDR_LEN 32
#define HTTP_ADDR_PORT_LEN 8
#define HTTP2_ADDR_LEN 32
#define HTTP2_ADDR_PORT_LEN 8

#define OWNERID_LEN 32
#define VEHICLEID_LEN 32
#define VEHICLEMODEL_LEN 32
#define DEVICEMODEL_LEN 32
#define PLATENUMBER_LEN 32
#define FIRMWAREDIR_LEN 128
#define FIRMWAREPREFIX_LEN 32
#define DRIVERNAME_LEN 128
#define VIN_LEN 128

typedef struct
{    
    // Network Settings
    char    HTTPServerAddr[HTTP_ADDR_LEN];
    char    HTTPServerPort[HTTP_ADDR_PORT_LEN];
    
    char    HTTPServerAddr2[HTTP2_ADDR_LEN];
    char    HTTPServerPort2[HTTP2_ADDR_PORT_LEN];
    
    int     MessagePerHour_Move;
    int     MessagePerHour_Idle;    
    int     ServerMessagePerHour;
    
    // Information
    char    OwnerId[OWNERID_LEN];
    char    VehicleId[VEHICLEID_LEN];
    char    VehicleModel[VEHICLEMODEL_LEN];
    char    DeviceModel[DEVICEMODEL_LEN];
    char    PlateNumber[PLATENUMBER_LEN]; 
    char    FirmwareDir[FIRMWAREDIR_LEN];
    char    FirmwarePrefix[FIRMWAREPREFIX_LEN];
    char    DriverName[DRIVERNAME_LEN];
    char    VIN[VIN_LEN];
    
    // BGTVT
    int     WarningVelocity;
    
    //Sensor
    bool    ActiveOnHigh_Door;
    bool    ActiveOnHigh_Engine;
    bool    ActiveOnHigh_AC;
    
    bool    HTTP_ProtocolEnable;
        
    int     PulseOnKm;    
    bool    OfflineMode;        
} VBB_Config;


#endif

#define CONFIG_STR "CK+CONFIG,"
#define OWNERID_STR "ownerid,"
#define VEHICLEID_STR "vehicleid,"
#define PLATE_STR "plate,"
#define MSGPERHOUR_MOVE_STR "msgperhourmove,"
#define MSGPERHOUR_IDLE_STR "msgperhouridle,"
#define HTTP_STR "http,"
#define HTTP2_STR "http2,"
#define PULSEKM_STR "pulsekm,"
#define WARNING_SPEED_STR "warningspeed,"
#define VIN_STR "vin,"
#define DRIVER_STR "driver,"

#define FLASH_OFFSET_OWNERID    0
#define FLASH_OFFSET_VEHICLEID  1
#define FLASH_OFFSET_VEHICLEMODEL 2
#define FLASH_OFFSET_PLATE 3
#define FLASH_OFFSET_MSGPERHOUR_MOVE 4
#define FLASH_OFFSET_MSGPERHOUR_IDLE 5
#define FLASH_OFFSET_HTTP 6
#define FLASH_OFFSET_HTTP2 7
#define FLASH_OFFSET_PULSEONKM 8
#define FLASH_OFFSET_ACTIVEDOOR 9
#define FLASH_OFFSET_ACTIVEENGINE 10
#define FLASH_OFFSET_OFFLINE 11
#define FLASH_OFFSET_FWDIR 12
#define FLASH_OFFSET_FWPREFIX 13
#define FLASH_OFFSET_DRIVER 14
#define FLASH_OFFSET_VIN 15
#define FLASH_OFFSET_WARNINGVEL 16
#define FLASH_OFFSET_PUSH 17
#define FLASH_OFFSET_HTTP_PROTOCOL 18




typedef struct
{    
    VBB_Flash flash;    
    VBB_Config config;    
    char tmpmsg[MESSAGE_SIZE];    
} VBB_Storage;

void vbb_STORAGE_Init(void);
void vbb_STORAGE_ReadConfig(void);
void vbb_STORAGE_AddConfig(const char * ConfigLine);
bool vbb_STORAGE_CheckConfig(const char * ConfigLine);
void vbb_STORAGE_Clear(void);

void vbb_STORAGE_Dump(void);
void vbb_STORAGE_SaveConfig(void);



#endif

